//
//  UserInviteFriendsController.m
//  HuLaQuan
//
//  Created by liyan on 16/1/27.
//  Copyright © 2016年 yuwubao. All rights reserved.
//

#import "UserInviteFriendsController.h"
#import "YuBlueButton.h"
#import <MessageUI/MessageUI.h>

@interface UserInviteFriendsController ()<MFMessageComposeViewControllerDelegate,UIAlertViewDelegate>
{
    UIViewController * _shareController;
}
@end

@implementation UserInviteFriendsController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)setupUI
{
    self.title = @"邀请好友";
    
    [self setupNavBackButton];
    
//    UIImageView *zcImage = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 50, 200, 200)];
//    zcImage.backgroundColor = [UIColor grayColor];
//    [self.view addSubview:zcImage];
//    
//    YuBlueButton *button = [[YuBlueButton alloc]init];
//    button.frame = CGRectMake(50, 300, (self.view.frame.size.width-100), 50);
//    button.backgroundColor = [UIColor blueColor];
//     [button setTitle:@"短信分享" forState:UIControlStateNormal];
//     [button addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button];
    
    
}
- (IBAction)shareAction:(id)sender {
    //[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://13888888888"]];
    
    [self showMessageView:[NSArray arrayWithObjects:@"15738852793", nil] title:@"gega"body:@"45455"];
    
    NSNumber *blue =  @13888888888;
//    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init] ;
//    if([MFMessageComposeViewController canSendText])
//    {
//        controller.body = @"Hello from Mugunth";
//        controller.recipients = [NSArray arrayWithObjects:@"15738852793", nil];
//        controller.messageComposeDelegate = self;
//        [self presentModalViewController:controller animated:YES];
 //   }
}
-(void)shareAction
{

    [self showMessageView:[NSArray arrayWithObjects:@13888888888,@13999999999, nil] title:@""body:@""];
}
#pragma mark MessageDelegate

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
    switch (result) {
        case MessageComposeResultSent:
            //信息传送成功
            
            break;
        case MessageComposeResultFailed:
            //信息传送失败
            
            break;
        case MessageComposeResultCancelled:
            //信息被用户取消传送
        {NSLog(@"取消");}
            break;
        default:
            break;
    }
}
-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
    if( [MFMessageComposeViewController canSendText] )
    {
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = phones;
      //  controller.navigationBar.tintColor = [UIColor redColor];
        controller.body = body;
        NSLog(@" %@ %@ %@ -- %@",title,phones,body,controller.body,controller.recipients);
        controller.messageComposeDelegate = self;
        [self presentModalViewController:controller animated:YES];
        [self presentViewController:controller animated:YES completion:nil];
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                        message:@"该设备不支持短信功能"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
